<?php

namespace App\Http\Controllers\Index;


use App\Models\Company\CompanyBasic;
use App\Models\Company\CompanyJob;

class AdTailController extends CommonController{

    /**
     * 首页的广告尾巴
     * @param $cid
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAdTail($cid)
    {
        $cid = idDecryption($cid);//获取企业id
        $data = [];//要JSON返回的数据
        $companyinfo = CompanyBasic::where('id', '=', $cid)->first();//公司信息
        $jobinfo = CompanyJob::with(['company_basic'])->where("com_id", $cid)->where("job_status", 1)->orderBy('updatetime', 'desc')->paginate(12);//公司其它招聘信息
        //有公司有职位则url_type为2，有公司无职位则url_type为1
        if(isset($companyinfo)){
            $data['url_type'] = 2;
            $data['company']['company_name'] = $companyinfo->company_name;
            $data['company']['company_url'] = url('/comabout_'.idEncryption($companyinfo->id).'.html');
            //有公司无职位则直接返回JSON，不再执行
            if($jobinfo->total() == 0){
                $data['url_type'] = 1;
                return response()->json($data);
            }
            foreach($jobinfo as $k=>$v){
                $data['job'][$k]['job_title'] = $v->job_title;//职位名称
                $data['job'][$k]['job_url'] = url('/jobinfo_'.idEncryption($v->id).'.html');//职位链接
            }
        }else{
            $data['url_type'] = 0;
        }
        return response()->json($data);
    }
}